﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;  //引用Profile基类
using NationalD3.Application.ViewModels;
using NationalD3.Domain.Commands.Students;
using NationalD3.Domain.Entities;

namespace NationalD3.Application.AutoMapper
{
    public class ViewModelToDomainMappingProfile : Profile
    {
        public ViewModelToDomainMappingProfile()
        {

            //视图模型映射成 命令模型（todo..)
            //手动进行配置
            CreateMap<StudentViewModel, Student>()
             .ForPath(d => d.Address.Province, o => o.MapFrom(s => s.Province))
             .ForPath(d => d.Address.City, o => o.MapFrom(s => s.City))
             .ForPath(d => d.Address.County, o => o.MapFrom(s => s.County))
             .ForPath(d => d.Address.Street, o => o.MapFrom(s => s.Street))
             ;


            //视图模型 映射为命令模型
            CreateMap<StudentViewModel, RegisterStudentCommand>()
                .ConstructUsing(c => new RegisterStudentCommand(c.Name,c.Email,c.BirthDate,c.Phone,c.Province,c.City,c.County,c.Street));
            
            CreateMap<StudentViewModel, UpdateStudentCommand>()
                .ConstructUsing(c => new UpdateStudentCommand(c.Id,c.Name, c.Email, c.BirthDate, c.Phone, c.Province, c.City, c.County, c.Street));

        }
    }
}
